<html>
<head><meta charset="utf-8"><title>How to map same `T`s with different HirIds to same identi... · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html">How to map same `T`s with different HirIds to same identi...</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213063439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213063439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213063439">(Oct 12 2020 at 17:04)</a>:</h4>
<p>In the example below, I realized that <code>HirId</code> of <code>T</code> in <code>T: Copy</code> is different from the <code>HirId</code> of <code>T</code> in <code>where T: Clone</code>.<br>
Is there a canonical way to map these <code>T</code>s with different <code>HirId</code>s to a same identifier? Thank you <span aria-label="crab" class="emoji emoji-1f980" role="img" title="crab">:crab:</span> </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">struct</span> <span class="nc">A</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="p">(</span><span class="n">T</span><span class="p">);</span><span class="w"></span>
<span class="k">unsafe</span><span class="w"> </span><span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">Copy</span><span class="o">&gt;</span><span class="w"> </span><span class="nb">Sync</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">A</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"></span>
<span class="w">    </span><span class="k">where</span><span class="w"> </span><span class="n">T</span>: <span class="nb">Clone</span>
<span class="p">{}</span><span class="w"></span>
</code></pre></div>



<a name="213064681"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213064681" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213064681">(Oct 12 2020 at 17:18)</a>:</h4>
<p>I think I found a way: Using <code>HirId.owner</code> seems to do the job for me <span aria-label="crab" class="emoji emoji-1f980" role="img" title="crab">:crab:</span></p>



<a name="213066657"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213066657" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213066657">(Oct 12 2020 at 17:38)</a>:</h4>
<p>Oh wait, using <code>HirId.owner</code> was not the solution at all..</p>



<a name="213067377"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213067377" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213067377">(Oct 12 2020 at 17:46)</a>:</h4>
<p>not sure how to do this for HirIds, but for DefIds you can call <code>tcx.item_name</code> I think</p>



<a name="213067389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213067389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213067389">(Oct 12 2020 at 17:46)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.item_name">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.item_name</a></p>



<a name="213088953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213088953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> JOE1994 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213088953">(Oct 12 2020 at 21:37)</a>:</h4>
<p>I was able to solve my issue using <code>tcx.item_name</code>! Thank you :)</p>



<a name="213089012"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/How%20to%20map%20same%20%60T%60s%20with%20different%20HirIds%20to%20same%20identi.../near/213089012" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/How.20to.20map.20same.20.60T.60s.20with.20different.20HirIds.20to.20same.20identi.2E.2E.2E.html#213089012">(Oct 12 2020 at 21:38)</a>:</h4>
<p>you're welcome!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>